<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    .open {
        width: 150px;
        height: 30px;
        border-radius: 25px;
        border: none;
        background-image: linear-gradient(to right, red, yellow);
        color: white;
    }

    .box {
        width: 300px;
        height: 200px;
        background-color: beige;
        border-radius: 20px;
        display: flex;
        flex-direction: column;
        justify-content: space-around;
        align-items: center;
    }

    .box button {
        width: 150px;
        height: 30px;
        border: none;
        border-radius: 10px;
        color: white;
        background-image: linear-gradient(to right, red, yellow);
    }

    .mask {
        background-color: rgba(0, 0, 0, .5);
        position: fixed;
        right: 0;
        left: 0;
        top: 0;
        bottom: 0;
        display: flex;
        justify-content: center;
        align-items: center;
    }
</style>

<body>
    <div id="app">
        <!--  点击显示 -->
        <button class="open" @click="visibile=true">打开模态框</button>
        <!-- 先隐藏 -->
        <modal v-if="visibile" @hide="handleHide"></modal>
    </div>
</body>

</html>
<template id="modal">
    <div class="mask">
        <div class="box">
            <span>提示</span>
            <span>提示内容</span>
            <button @click="makeSure">确定</button>
        </div>
    </div>

</template>
<script src='https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js'></script>
<script>
    //组件 子=>父
    Vue.component("modal", {
        template: "#modal",
        methods: {
            makeSure() {
                this.$emit("hide", 777)
            }
        }
    })

    let vm = new Vue({
        el: "#app",
        data: {
            visibile: false
        },
        methods: {
            handleHide(a) {
                console.log(a)
                this.visibile = false
            }
        }

    })
</script>